package com.study.util;


import java.util.List;

public class StringUtil {

    public static boolean isNotBlank(String str) {
        int length;

        if ((str == null) || ((length = str.length()) == 0)) {
            return false;
        }

        for (int i = 0; i < length; i++) {
            if (!Character.isWhitespace(str.charAt(i))) {
                return true;
            }
        }

        return false;
    }

    public static String build(String... strs) {
        StringBuilder stringBuilder = new StringBuilder();
        for (int i = 0; i < strs.length; i++) {
            stringBuilder.append(strs[i]);
        }
        return stringBuilder.toString();
    }

    /**
     * @param fieldNames
     */
    public static String makeLikeSQL(String value, String... fieldNames) {
        StringBuilder stringBuilder = new StringBuilder(16);
        stringBuilder.append("(");
        for (int i = 0; i < fieldNames.length; i++) {
            stringBuilder.append(fieldNames[i]).append(" like \"").append(value).append("\"");
            if (i < fieldNames.length - 1) {
                stringBuilder.append(" or ");
            }
        }
        stringBuilder.append(")");
        return stringBuilder.toString();
    }

    public static String join(List<String> strList, String middle) {
        StringBuilder stringBuilder = new StringBuilder();
        for (int i = 0; i < strList.size(); i++) {
            stringBuilder.append(strList.get(i));
            if (middle != null) {
                stringBuilder.append("\n");
            }
        }
        return stringBuilder.toString();
    }
}
